﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.BLL.Statistics;
using MINERP.MODEL.FoundationModel;
using FastReport;

namespace MINERP.Statistics.Forms
{
    public partial class FrmInnerStat : Form
    {
        public FrmInnerStat()
        {
            InitializeComponent();
        }

        private void FrmInnerStat_Load(object sender, EventArgs e)
        {
            //comboBoxType.SelectedIndex = 0;
            comboBoxDutyName.DataSource = _bll.GetUser();
            comboBoxDutyName.DisplayMember = "UserName";
            comboBoxDutyName.ValueMember = "UserID";
            dateTimePickerStart.DateTime = DateTime.Now;
            dateTimePickerEnd.DateTime = DateTime.Now;

            comboBoxFromName.DataSource = _bll.GetUser();
            comboBoxFromName.DisplayMember = "UserName";
            comboBoxFromName.ValueMember = "UserID";
        }
        private InnerStatBLL _bll = new InnerStatBLL();

        private void buttonOK_Click(object sender, EventArgs e)
        {
            buttonOK.Enabled = false;
            int intDutyId=((User_Info)(comboBoxDutyName.SelectedItem)).UserID;
            int intFromID = ((User_Info) (comboBoxFromName.SelectedItem)).UserID;

            DataSet ds;
            Report fasrReport = new Report();
            fasrReport.Preview = previewControl1;
            ds = _bll.GetInnerData(0, dateTimePickerStart.DateTime.Date, dateTimePickerEnd.DateTime.Date.AddDays(1), intDutyId, intFromID);
            fasrReport.Load(Application.StartupPath + "\\Report\\InnerStatA.frx");

            ds.WriteXml(@"C:\windows\xmlData\innerstat.xml", XmlWriteMode.WriteSchema);
           
            try
            {
               
              
                fasrReport.SetParameterValue("StartTime", dateTimePickerStart.Text);
                fasrReport.SetParameterValue("EndTime", dateTimePickerEnd.Text);
                // fasrReport.SetParameterValue("Type", this.comboBoxType.SelectedIndex.ToString());

                previewControl1.Refresh();
                previewControl1.Show();
                fasrReport.Show();

                //fasrReport.Export(
                //fasrReport.Show();
            }
            catch { }
            finally
            {
                buttonOK.Enabled = true;
            };
        }

        
    }
}
